package com.text.day2_5;

import com.text.day2_4.teampk.People;

import java.util.Random;

public class PeopleSon extends People {
    public PeopleSon(String name, int hp, int atc) {
        super(name, hp, atc);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {    //this  是这个当前对象
            return true;
        }
        if (obj instanceof PeopleSon) {
            PeopleSon another = (PeopleSon) obj;
            return another.getName().equals(this.getName()) && another.getHp() == this.getHp() && another.getAtc() == this.getAtc();
        }


        return false;
    }

    public static void main(String[] args) {
        Random random = new Random();
        PeopleSon peopleSon1 = new PeopleSon("一号", 100, random.nextInt(20) + 20);
        PeopleSon peopleSon2 = new PeopleSon("二号", 100, random.nextInt(20) + 20);
        System.out.println(peopleSon1);
        System.out.println(peopleSon2);
        System.out.println(peopleSon1.equals(peopleSon2));
        peopleSon1 = new PeopleSon("一号", 100, 20);
        peopleSon2 = new PeopleSon("一号", 100, 20);
        System.out.println(peopleSon1);
        System.out.println(peopleSon2);
        System.out.println(peopleSon1.equals(peopleSon2));
    }
}
